package com.tbit.main.service.impl;

import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.dao.core.CameraDao;
import com.tbit.main.pojo.Camera;
import com.tbit.main.service.CameraService;
import com.tbit.main.util.StringUtil;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LMY
 * @create 2022-07-12 16:02
 */
@Service("cameraService")
public class CameraServiceImpl implements CameraService {

    @Autowired
    private CameraDao cameraMapper;

    @Override
    public Camera getMachineNO(String machineNO) {
        return cameraMapper.getMachineNO(machineNO);
    }

    @Override
    public List<Camera> getMachineNOs(List<String> machineNOs) {
        return cameraMapper.getMachineNOs(StringUtil.getStringListString(machineNOs));
    }

    @Override
    public List<Camera> getAccountIdTime(Integer accountId, String time) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, accountId);
        map.put("time", time);
        return cameraMapper.getAccountIdTime(map);
    }

    @Override
    public List<String> getMachineNOsTime(List<String> machineNOs, String time) {
        Map<String, Object> map = new HashMap<>();
        map.put("machineNOs", StringUtil.getStringListString(machineNOs));
        map.put("time", time);
        return cameraMapper.getMachineNOsTime(map);
    }

    @Override
    public void update(Camera camera) {
        cameraMapper.update(camera);
    }

    @Override
    public void insert(Camera camera) {
        cameraMapper.insert(camera);
    }

    @Override
    public void delete(String machineNO) {
        cameraMapper.delete(machineNO);
    }

    @Override
    public void deleteS(List<String> machineNOS) {
        List<List<String>> parkPointGeo = ListUtils.partition(machineNOS, 900);
        for (List<String> parkPoint : parkPointGeo) {
            cameraMapper.deleteS(StringUtil.getStringListString(parkPoint));
        }

    }

    @Override
    public List<String> getNotExist() {
        return cameraMapper.getNotExist();
    }
}
